



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>上篇：nginx模块开发篇 &mdash; Nginx开发从入门到精通</title>
    <link rel="stylesheet" href="_static/book.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="_static/comment.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '0.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../js/??ga.js,correctpng.js?v=1"></script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/booktools.js"></script>
    <script type="text/javascript" src="_static/translations.js"></script>
    <script type="text/javascript" src="_static/comment.js"></script>
    <link rel="top" title="Nginx开发从入门到精通" href="index.html" />
    <link rel="next" title="背景介绍" href="chapter_01.html" />
    <link rel="prev" title="Nginx开发从入门到精通" href="index.html" /> 
  </head>
  <body lang="zh-Hans">
    <div class="related">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="chapter_01.html" title="背景介绍"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="index.html" title="Nginx开发从入门到精通"
             accesskey="P">上一页</a> |</li>
        <li><a href="index.html">Nginx开发从入门到精通</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="nginx">
<h1>上篇：nginx模块开发篇<a class="headerlink" href="#nginx" title="永久链接至标题">¶</a></h1>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="chapter_01.html">背景介绍</a><ul>
<li class="toctree-l2"><a class="reference internal" href="chapter_01.html#nginx">nginx历史</a></li>
<li class="toctree-l2"><a class="reference internal" href="chapter_01.html#id2">使用简介</a></li>
<li class="toctree-l2"><a class="reference internal" href="chapter_01.html#id3">nginx特点介绍</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="chapter_02.html">nginx平台初探(100%)</a><ul>
<li class="toctree-l2"><a class="reference internal" href="chapter_02.html#id1">初探nginx架构(100%)</a></li>
<li class="toctree-l2"><a class="reference internal" href="chapter_02.html#id2">nginx基础概念(100%)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#connection">connection</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#request">request</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_02.html#id3">基本数据结构(99%)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#ngx-str-t-100">ngx_str_t(100%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#ngx-pool-t-100">ngx_pool_t(100%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#ngx-array-t-100">ngx_array_t(100%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#ngx-hash-t-100">ngx_hash_t(100%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#ngx-hash-wildcard-t-100">ngx_hash_wildcard_t(100%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#ngx-hash-combined-t-100">ngx_hash_combined_t(100%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#ngx-hash-keys-arrays-t-100">ngx_hash_keys_arrays_t(100%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#ngx-chain-t-100">ngx_chain_t(100%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#ngx-buf-t-99">ngx_buf_t(99%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#ngx-list-t-100">ngx_list_t(100%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#ngx-queue-t-100">ngx_queue_t(100%)</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_02.html#id6">nginx的配置系统(100%)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#id7">指令概述</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#id8">指令参数</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#id9">指令上下文</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_02.html#nginx">nginx的模块化体系结构</a></li>
<li class="toctree-l2"><a class="reference internal" href="chapter_02.html#id10">模块概述</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#id11">模块的分类</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_02.html#id12">nginx的请求处理</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_02.html#id13">请求的处理流程</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="chapter_03.html">handler模块(100%)</a><ul>
<li class="toctree-l2"><a class="reference internal" href="chapter_03.html#handler">handler模块简介</a></li>
<li class="toctree-l2"><a class="reference internal" href="chapter_03.html#id1">模块的基本结构</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_03.html#id2">模块配置结构</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_03.html#id3">模块配置指令</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_03.html#id4">模块上下文结构</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_03.html#id5">模块的定义</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_03.html#id6">handler模块的基本结构</a></li>
<li class="toctree-l2"><a class="reference internal" href="chapter_03.html#id7">handler模块的挂载</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_03.html#id8">按处理阶段挂载</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_03.html#id9">按需挂载</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_03.html#id10">handler的编写步骤</a></li>
<li class="toctree-l2"><a class="reference internal" href="chapter_03.html#hello-handler">示例: hello handler 模块</a></li>
<li class="toctree-l2"><a class="reference internal" href="chapter_03.html#id11">handler模块的编译和使用</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_03.html#config">config文件的编写</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_03.html#id12">编译</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_03.html#id13">使用</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_03.html#id14">更多handler模块示例分析</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_03.html#http-access-module">http access module</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_03.html#http-static-module">http static module</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_03.html#http-log-module">http log module</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="chapter_04.html">过滤模块 (90%)</a><ul>
<li class="toctree-l2"><a class="reference internal" href="chapter_04.html#id2">过滤模块简介 (90%)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_04.html#id3">执行时间和内容 (90%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_04.html#id4">执行顺序 (90%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_04.html#id5">模块编译 (90%)</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_04.html#id6">过滤模块的分析 (90%)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_04.html#id7">相关结构体 (90%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_04.html#id8">响应头过滤函数 (90%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_04.html#id9">响应体过滤函数 (90%)</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="chapter_05.html">upstream模块</a><ul>
<li class="toctree-l2"><a class="reference internal" href="chapter_05.html#upstream-100">upstream模块 (100%)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_05.html#id1">upstream模块接口</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_05.html#memcached">memcached模块分析</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_05.html#id4">本节回顾</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_05.html#id5">负载均衡模块 (100%)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_05.html#id6">配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_05.html#id7">指令</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_05.html#id8">钩子</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_05.html#id9">初始化配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_05.html#id10">初始化请求</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_05.html#peer-getpeer-free">peer.get和peer.free回调函数</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_05.html#id11">本节回顾</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="chapter_06.html">其他模块 (40%)</a><ul>
<li class="toctree-l2"><a class="reference internal" href="chapter_06.html#core-40">core模块 (40%)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_06.html#nginx-40">Nginx的启动模块 (40%)</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_06.html#event-40">event模块 (40%)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_06.html#id2">event的类型和功能 (40%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_06.html#accept-40">accept锁 (40%)</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_06.html#id3">定时器 (40%)</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_06.html#mail">mail模块</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_06.html#id4">mail模块的实现</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_06.html#id5">mail模块的功能</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="chapter_07.html">模块开发高级篇(30%)</a><ul>
<li class="toctree-l2"><a class="reference internal" href="chapter_07.html#id2">变量(80%)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_07.html#id3">综述</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_07.html#id4">创建变量</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_07.html#id5">使用变量</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_07.html#upstream">upstream</a><ul>
<li class="toctree-l3"><a class="reference internal" href="chapter_07.html#subrequestupstream">使用subrequest访问upstream</a></li>
<li class="toctree-l3"><a class="reference internal" href="chapter_07.html#id6">超越upstream</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="chapter_07.html#lua">使用lua模块</a></li>
</ul>
</li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="http://tengine.taobao.org/">
              <img class="logo" src="_static/logo.png" alt="Logo"/>
            </a></p>
  <h4>上一个主题</h4>
  <p class="topless"><a href="index.html"
                        title="上一章">Nginx开发从入门到精通</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="chapter_01.html"
                        title="下一章">背景介绍</a></p>
  <h3>本页</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/module_development.txt"
           rel="nofollow">显示源代码</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>快速搜索</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="搜索" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    输入相关的模块，术语，类或者函数名称进行搜索
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="chapter_01.html" title="背景介绍"
             >下一页</a> |</li>
        <li class="right" >
          <a href="index.html" title="Nginx开发从入门到精通"
             >上一页</a> |</li>
        <li><a href="index.html">Nginx开发从入门到精通</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; 版权所有 2012, taobao.
      使用 <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>